package com.lv.service.dialog

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.LogUtils
import com.github.gzuliyujiang.wheelpicker.widget.LinkageWheelLayout
import com.lv.common.imp.OnPositionMore
import com.lv.common.utils.TimeUtil
import com.lv.common.utils.YgxUtilsKt
import com.lv.common.utils.showToast
import com.lv.common.widget.linkbar.ZFlowLayout
import com.lv.service.R
import com.lv.service.bean.CommonSelectedBean
import com.lv.service.room.category.CategoryBean
import com.lv.service.utils.YgxToolsKt
import com.lv.service.weidget.picker.ThirdLikeProvider
import com.lxj.xpopup.core.BottomPopupView

/**
 * 作者： ygx
 * 创建日期：2022/10/10 10:32 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：
 */
class Time2StepTabPopupView(
    private val mContext: Context,
    private val mAllBeans: List<CategoryBean>?,
    private val mAllCusBeans: List<CategoryBean>?,
    private val mOpenBeans: List<CommonSelectedBean>? = null,
    private var currentTopProvin: Int = -1,
    private var mWheelPosition1: Int = 0,
    private var mWheelPosition2: Int = 0,
    private var mWheelPosition3: Int = 0,
    private var mWheelStartPosition1: Int = 0,
    private var mWheelStartPosition2: Int = 0,
    private var mWheelStartPosition3: Int = 0,
    private var mWheelEndPosition1: Int = 0,
    private var mWheelEndPosition2: Int = 0,
    private var mWheelEndPosition3: Int = 0,
    private var mStartTime: String = "",
    private var mEndTime: String = "",
    private var mWheelPos: Int? = 0,//显示第几个 -1 全部显示
    private val positionListener: OnPositionMore<String>? = null
) :
    BottomPopupView(mContext), OnClickListener {
    private var tvTabDay: TextView? = null
    private var tvTabMonth: TextView? = null
    private var tvTabYear: TextView? = null
    private var tvTitleCustom: TextView? = null
    private var tvStart: TextView? = null
    private var tvEnd: TextView? = null
    private var tvSure: TextView? = null
    private var mFlowLayout: ZFlowLayout? = null
    private var wheelLinkage: LinkageWheelLayout? = null
    private var wheelLinkageCus: LinkageWheelLayout? = null
    private var clContainerTop: ConstraintLayout? = null
    private var ivClose: ImageView? = null
    private var tvLine1: View? = null
    private var tvLine2: View? = null
    private var tvLine3: View? = null
    private var tvLine4: View? = null
    private var viewStartLine: View? = null
    private var viewEndLine: View? = null
    private var viewTop: View? = null
    private var timeCurrent: Int = 0
    private val mMonday = TimeUtil.getDayOfWeek(1, "yyyy-MM-dd")//本周一的日期
    private val mTodayday = TimeUtil.getNowDateTime("yyyy-MM-dd")//今天的日期
    private var mProMonday = ""//上周一的日期
    private var mProSunday = ""//上周日的日期
    private var mPro2Monday = ""//上上周一的日期
    private var mPro2Sunday = ""//上上周日的日期
    private var mMonth = String.format("%02d", TimeUtil.getMonth()) //当前月

    private val mViewList = mutableListOf<View>()

    override fun getImplLayoutId(): Int {
        return R.layout.time_2step_tab_popup
    }

    override fun onCreate() {
        super.onCreate()
        //上上周
        mPro2Monday = TimeUtil.getPreviousDaysDate(14, mMonday, "yyyy-MM-dd")
        mPro2Sunday = TimeUtil.getBeforDaysDate(6, mPro2Monday, "yyyy-MM-dd")

        //上周
        mProMonday = TimeUtil.getPreviousDaysDate(7, mMonday, "yyyy-MM-dd")
        mProSunday = TimeUtil.getBeforDaysDate(6, mProMonday, "yyyy-MM-dd")


        viewTop = findViewById<View>(R.id.view_top)
        tvTabDay = findViewById<TextView>(R.id.tv_tab_day)
        tvTabMonth = findViewById<TextView>(R.id.tv_tab_month)
        tvTabYear = findViewById<TextView>(R.id.tv_tab_year)
        tvTitleCustom = findViewById<TextView>(R.id.tv_title_custom)
        tvStart = findViewById<TextView>(R.id.tv_start)
        tvEnd = findViewById<TextView>(R.id.tv_end)
        tvSure = findViewById<TextView>(R.id.tv_sure)
        mFlowLayout = findViewById<ZFlowLayout>(R.id.z_flow)
        wheelLinkage = findViewById<LinkageWheelLayout>(R.id.wheel_linkage)
        wheelLinkageCus = findViewById<LinkageWheelLayout>(R.id.wheel_linkage_cus)
        clContainerTop = findViewById<ConstraintLayout>(R.id.cl_container_top)
        ivClose = findViewById<ImageView>(R.id.iv_close)
        tvLine1 = findViewById<View>(R.id.tv_line1)
        tvLine2 = findViewById<View>(R.id.tv_line2)
        tvLine3 = findViewById<View>(R.id.tv_line3)
        tvLine4 = findViewById<View>(R.id.tv_line4)
        viewStartLine = findViewById<View>(R.id.view_start_line)
        viewEndLine = findViewById<View>(R.id.view_end_line)
        viewTop?.setOnClickListener(this)
        tvTabDay?.setOnClickListener(this)
        tvTabMonth?.setOnClickListener(this)
        tvTabYear?.setOnClickListener(this)
        tvTitleCustom?.setOnClickListener(this)
        tvSure?.setOnClickListener(this)
        ivClose?.setOnClickListener(this)
        tvStart?.setOnClickListener(this)
        tvEnd?.setOnClickListener(this)
        initView()
        initEvnet()
        initUI()
        initCustomTime()
    }

    private fun initView() {

        val thirdLikeProvider = ThirdLikeProvider(mAllBeans)
        wheelLinkage?.setData(thirdLikeProvider)
        val thirdLikeCusProvider = ThirdLikeProvider(mAllCusBeans)
        wheelLinkageCus?.setData(thirdLikeCusProvider)

        wheelLinkage?.setDefaultValue(mWheelPosition1, mWheelPosition2, mWheelPosition3)
        wheelLinkageCus?.setDefaultValue(
            mWheelStartPosition1,
            mWheelStartPosition2,
            mWheelStartPosition3
        )
        wheelLinkage?.firstWheelView?.visibility = View.VISIBLE
        wheelLinkage?.secondWheelView?.visibility = View.VISIBLE
        wheelLinkage?.thirdWheelView?.visibility = View.VISIBLE
        wheelLinkageCus?.firstWheelView?.visibility = View.VISIBLE
        wheelLinkageCus?.secondWheelView?.visibility = View.VISIBLE
        wheelLinkageCus?.thirdWheelView?.visibility = View.VISIBLE
        setFlowData()
    }

    private fun initUI() {
        when (mWheelPos) {// 0 今天 1 本周 2 本月 3 24H 4 按月 5 按年 6 上上周 7 上周 8 本周 9 自定义时间
            -1, 0, 3 -> {//三级
                wheelLinkage?.visibility = View.VISIBLE
                tvLine1?.visibility = View.VISIBLE
                wheelLinkage?.firstWheelView?.visibility = View.VISIBLE
                wheelLinkage?.secondWheelView?.visibility = View.VISIBLE
                wheelLinkage?.thirdWheelView?.visibility = View.VISIBLE
                wheelLinkageCus?.visibility = View.GONE
                clContainerTop?.visibility = View.GONE
                tvLine2?.visibility = View.GONE
                tvLine3?.visibility = View.GONE
                tvLine4?.visibility = View.GONE
            }
            5 -> {//一级
                wheelLinkage?.visibility = View.VISIBLE
                tvLine3?.visibility = View.VISIBLE
                wheelLinkage?.firstWheelView?.visibility = View.VISIBLE
                wheelLinkage?.secondWheelView?.visibility = View.GONE
                wheelLinkage?.thirdWheelView?.visibility = View.GONE
                wheelLinkageCus?.visibility = View.GONE
                clContainerTop?.visibility = View.GONE
                tvLine1?.visibility = View.GONE
                tvLine2?.visibility = View.GONE
                tvLine4?.visibility = View.GONE
            }
            2, 4 -> {//二级
                wheelLinkage?.visibility = View.VISIBLE
                tvLine2?.visibility = View.VISIBLE
                wheelLinkage?.firstWheelView?.visibility = View.VISIBLE
                wheelLinkage?.secondWheelView?.visibility = View.VISIBLE
                wheelLinkage?.thirdWheelView?.visibility = View.GONE
                wheelLinkageCus?.visibility = View.GONE
                clContainerTop?.visibility = View.GONE
                tvLine1?.visibility = View.GONE
                tvLine3?.visibility = View.GONE
                tvLine4?.visibility = View.GONE
            }
            1, 8 -> {//本周
                wheelLinkage?.visibility = View.GONE
                tvLine1?.visibility = View.GONE
                tvLine2?.visibility = View.GONE
                tvLine3?.visibility = View.GONE
                wheelLinkageCus?.visibility = View.VISIBLE
                clContainerTop?.visibility = View.VISIBLE
                tvLine4?.visibility = View.VISIBLE


            }

            else -> {//自定义(16789)
                wheelLinkage?.visibility = View.GONE
                tvLine1?.visibility = View.GONE
                tvLine2?.visibility = View.GONE
                tvLine3?.visibility = View.GONE
                wheelLinkageCus?.visibility = View.VISIBLE
                clContainerTop?.visibility = View.VISIBLE
                tvLine4?.visibility = View.VISIBLE
            }

        }
    }

    private fun initCustomTime() {
        when (timeCurrent) {
            0 -> {
                if (mStartTime.isEmpty()) {
                    mWheelStartPosition1 = (mAllCusBeans?.size ?: 0) - 1
                    mWheelStartPosition2 =
                        (mAllCusBeans?.get(mWheelStartPosition1)?.telSecondCategories?.size
                            ?: 0) - 1
                    mWheelStartPosition3 =
                        (mAllCusBeans?.get(mWheelStartPosition1)?.telSecondCategories?.get(
                            mWheelStartPosition2
                        )?.telThirdCategories?.size ?: 0) - 1
                    mStartTime = "${mAllCusBeans?.get(mWheelStartPosition1)?.name}-${
                        mAllCusBeans?.get(mWheelStartPosition1)?.telSecondCategories?.get(
                            mWheelStartPosition2
                        )?.name
                    }-${
                        mAllCusBeans?.get(mWheelStartPosition1)?.telSecondCategories?.get(
                            mWheelStartPosition2
                        )?.telThirdCategories?.get(mWheelStartPosition3)?.name
                    }"
                } else {
                    initStartScanTimePicker()
                }
                wheelLinkageCus?.setDefaultValue(
                    mWheelStartPosition1,
                    mWheelStartPosition2,
                    mWheelStartPosition3
                )
                tvStart?.text = mStartTime
                tvEnd?.text = mEndTime
                tvStart?.setTextColor(Color.parseColor("#eb613d"))
                viewStartLine?.setBackgroundResource(com.lv.common.R.drawable.bg_theme_2)
                tvEnd?.setTextColor(Color.parseColor("#242424"))
                viewEndLine?.setBackgroundResource(com.lv.common.R.drawable.bg_24_2)
            }
            1 -> {
                if (mEndTime.isEmpty()) {
                    mWheelEndPosition1 = (mAllCusBeans?.size ?: 0) - 1
                    mWheelEndPosition2 =
                        (mAllCusBeans?.get(mWheelEndPosition1)?.telSecondCategories?.size ?: 0) - 1
                    mWheelEndPosition3 =
                        (mAllCusBeans?.get(mWheelEndPosition1)?.telSecondCategories?.get(
                            mWheelEndPosition2
                        )?.telThirdCategories?.size ?: 0) - 1
                    mEndTime = "${mAllCusBeans?.get(mWheelEndPosition1)?.name}-${
                        mAllCusBeans?.get(mWheelEndPosition1)?.telSecondCategories?.get(
                            mWheelEndPosition2
                        )?.name
                    }-${
                        mAllCusBeans?.get(mWheelEndPosition1)?.telSecondCategories?.get(
                            mWheelEndPosition2
                        )?.telThirdCategories?.get(mWheelEndPosition3)?.name
                    }"
                } else {
                    initEndScanTimePicker()
                }
                wheelLinkageCus?.setDefaultValue(
                    mWheelEndPosition1,
                    mWheelEndPosition2,
                    mWheelEndPosition3
                )
                tvStart?.text = mStartTime
                tvEnd?.text = mEndTime
                tvStart?.setTextColor(Color.parseColor("#242424"))
                viewStartLine?.setBackgroundResource(com.lv.common.R.drawable.bg_24_2)
                tvEnd?.setTextColor(Color.parseColor("#eb613d"))
                viewEndLine?.setBackgroundResource(com.lv.common.R.drawable.bg_theme_2)
            }
        }
    }

    private fun initStartScanTimePicker() {
        val list = mutableListOf<CategoryBean>()
        mAllCusBeans?.let { list.addAll(it) }
        val startSplit = mStartTime.split("-")
        val (x, y, z) = YgxToolsKt.initThirdAddressInt(
            list,
            startSplit[0],
            String.format("%02d", startSplit[1].toDouble().toInt()),
            String.format("%02d", startSplit[2].toDouble().toInt())
        )
        mWheelStartPosition1 = x
        mWheelStartPosition2 = y
        mWheelStartPosition3 = z
    }

    private fun initEndScanTimePicker() {
        val list = mutableListOf<CategoryBean>()
        mAllCusBeans?.let { list.addAll(it) }
        val endSplit = mEndTime.split("-")
        val (a, b, c) = YgxToolsKt.initThirdAddressInt(
            list,
            endSplit[0],
            String.format("%02d", endSplit[1].toDouble().toInt()),
            String.format("%02d", endSplit[2].toDouble().toInt())
        )
        mWheelEndPosition1 = a
        mWheelEndPosition2 = b
        mWheelEndPosition3 = c
    }

    private fun initEvnet() {
        wheelLinkage?.setOnLinkageSelectedListener { first, second, third ->
            mWheelPosition1 = wheelLinkage?.firstWheelView?.currentPosition ?: 0
            mWheelPosition2 = wheelLinkage?.secondWheelView?.currentPosition ?: 0
            mWheelPosition3 = wheelLinkage?.thirdWheelView?.currentPosition ?: 0

            val month =
                mAllCusBeans?.get(mWheelPosition1)?.telSecondCategories?.get(mWheelPosition2)?.name
            val time = "${mAllCusBeans?.get(mWheelPosition1)?.name}-${month}-${
                mAllCusBeans?.get(mWheelPosition1)?.telSecondCategories?.get(
                    mWheelPosition2
                )?.telThirdCategories?.get(mWheelPosition3)?.name
            }"
            mStartTime = time
            when (mWheelPos) {// 0 今天 1 本周 2 本月 3 24H 4 按月 5 按年 6 上上周 7 上周 8 本周 9 自定义时间
                0 -> {
                    if (time != mTodayday) {
                        mWheelPos = 3
                    }
                }
                2 -> {//2 本月
                    if (mMonth == month) {
                        mWheelPos = 2
                    } else {
                        mWheelPos = 4
                    }
                }
                3 -> {
                    if (time == mTodayday) {
                        mWheelPos = 0
                    }
                }
                4 -> {
                    if (mMonth == month) {
                        mWheelPos = 2
                    }
                }
            }

//            mBinding.tvSearchCategory.text =
//                "${mAllBeans!![mWheelPosition1].name}-${mAllBeans[mWheelPosition1].telSecondCategories!![mWheelPosition2].name}"
        }
        wheelLinkageCus?.setOnLinkageSelectedListener { first, second, third ->
            val position1 = wheelLinkageCus?.firstWheelView?.currentPosition ?: 0
            val position2 = wheelLinkageCus?.secondWheelView?.currentPosition ?: 0
            val position3 = wheelLinkageCus?.thirdWheelView?.currentPosition ?: 0
            val time = "${mAllCusBeans?.get(position1)?.name}-${
                mAllCusBeans?.get(position1)?.telSecondCategories?.get(
                    position2
                )?.name
            }-${
                mAllCusBeans?.get(position1)?.telSecondCategories?.get(
                    position2
                )?.telThirdCategories?.get(position3)?.name
            }"
            when (timeCurrent) {
                0 -> {
                    mWheelStartPosition1 = position1
                    mWheelStartPosition2 = position2
                    mWheelStartPosition3 = position3
                    mStartTime = time
                    tvStart?.text = mStartTime
                }
                1 -> {
                    mWheelEndPosition1 = position1
                    mWheelEndPosition2 = position2
                    mWheelEndPosition3 = position3
                    mEndTime = time
                    tvEnd?.text = mEndTime
                }
            }
            initTagView()

//            mBinding.tvSearchCategory.text =
//                "${mAllBeans!![mWheelPosition1].name}-${mAllBeans[mWheelPosition1].telSecondCategories!![mWheelPosition2].name}"
        }

    }

    private fun initTagView() {
        mViewList.forEach { viewItem ->
            viewItem.setBackgroundResource(com.lv.common.R.drawable.bg_f9_15)
        }
        mOpenBeans?.forEach { viewItem ->
            viewItem.selected = false
        }
        LogUtils.e("mStartTime==${mStartTime}==mMonday==${mMonday}==mEndTime==${mEndTime}==mTodayday==${mTodayday}")
        LogUtils.e("mStartTime==${mStartTime}==mProMonday==${mProMonday}==mEndTime==${mEndTime}==mProSunday==${mProSunday}")
        LogUtils.e("mStartTime==${mStartTime}==mPro2Monday==${mPro2Monday}==mEndTime==${mEndTime}==mPro2Sunday==${mPro2Sunday}")
        if (mStartTime == mMonday && mEndTime == mTodayday) {//本周
            mWheelPos = 8
            mWheelPos = 1
            currentTopProvin = 2
        } else if (mStartTime == mProMonday && mEndTime == mProSunday) {//上周
            mWheelPos = 7
            currentTopProvin = 1
        } else if (mStartTime == mPro2Monday && mEndTime == mPro2Sunday) {//上上周
            currentTopProvin = 0
            mWheelPos = 6
        } else {
            mWheelPos = 9
            currentTopProvin = -1
        }
        if (currentTopProvin != -1) {
            mOpenBeans?.get(currentTopProvin)?.selected = true
            mViewList[currentTopProvin].setBackgroundResource(com.lv.common.R.drawable.bg_tab_eb613d_14)
        }
    }

    private fun setFlowData() {
        mViewList.clear()
        if (!mOpenBeans.isNullOrEmpty()) {
            for (i in 0 until mOpenBeans.size) {
                val textChild = LayoutInflater.from(mContext)
                    .inflate(
                        R.layout.text_tag_layout_gray,
                        mFlowLayout, false
                    ) as TextView
                textChild.text = mOpenBeans[i].name
                mViewList.add(textChild)
            }
            if (currentTopProvin != -1) {
                mViewList[currentTopProvin].setBackgroundResource(com.lv.common.R.drawable.bg_tab_eb613d_14)
            }

            mFlowLayout?.setChildren(mViewList)
            mFlowLayout?.setOnTagClickListener { view, position ->
                mViewList.forEach { viewItem ->
                    viewItem.setBackgroundResource(com.lv.common.R.drawable.bg_f9_15)
                }
                mOpenBeans.forEach { viewItem ->
                    viewItem.selected = false
                }
                currentTopProvin = position
                mOpenBeans[position].selected = true
                mViewList[position].setBackgroundResource(com.lv.common.R.drawable.bg_tab_eb613d_14)

                when (position) {
                    0 -> {//上上周
                        mWheelPos = 6
                        mStartTime = mPro2Monday
                        mEndTime = mPro2Sunday
                    }
                    1 -> {//上周
                        mWheelPos = 7
                        mStartTime = mProMonday
                        mEndTime = mProSunday
                    }
                    2 -> {//本周
                        mWheelPos = 8
                        mStartTime = mMonday
                        mEndTime = mTodayday
                    }
                }

                initStartScanTimePicker()
                initEndScanTimePicker()

                when (timeCurrent) {
                    0 -> {
                        wheelLinkageCus?.setDefaultValue(
                            mWheelStartPosition1,
                            mWheelStartPosition2,
                            mWheelStartPosition3
                        )
                        tvStart?.text = mStartTime
                        tvEnd?.text = mEndTime
                        tvStart?.setTextColor(Color.parseColor("#eb613d"))
                        viewStartLine?.setBackgroundResource(com.lv.common.R.drawable.bg_theme_2)
                        tvEnd?.setTextColor(Color.parseColor("#242424"))
                        viewEndLine?.setBackgroundResource(com.lv.common.R.drawable.bg_24_2)
                    }
                    1 -> {
                        wheelLinkageCus?.setDefaultValue(
                            mWheelEndPosition1,
                            mWheelEndPosition2,
                            mWheelEndPosition3
                        )
                        tvStart?.text = mStartTime
                        tvEnd?.text = mEndTime
                        tvStart?.setTextColor(Color.parseColor("#242424"))
                        viewStartLine?.setBackgroundResource(com.lv.common.R.drawable.bg_24_2)
                        tvEnd?.setTextColor(Color.parseColor("#eb613d"))
                        viewEndLine?.setBackgroundResource(com.lv.common.R.drawable.bg_theme_2)
                    }
                }
//                mPosition4Listener?.onClick(position, -1, -1, -1)
//                dismiss()
            }
        }

    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun beforeDismiss() {
        super.beforeDismiss()

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.view_top, R.id.iv_close -> {
//                positionListener?.onClick(
//                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, data = null
//                )
                dismiss()
            }
            R.id.tv_tab_day -> {// 0 今天 1 本周 2 本月 3 24H 4 按月 5 按年 6 上上周 7 上周 8 本周 9 自定义时间
                if (mWheelPos != 3) {
                    getWheelCurrentTime()
                    mWheelPos = 3
                    initUI()
                }
            }
            R.id.tv_tab_month -> {
                if (mWheelPos != 4) {
                    getWheelCurrentTime()
                    mWheelPos = 4
                    initUI()
                }
            }
            R.id.tv_tab_year -> {
                if (mWheelPos != 5) {
                    getWheelCurrentTime()
                    mWheelPos = 5
                    initUI()
                }
            }

            R.id.tv_title_custom -> {
                if (mWheelPos != 9) {
                    mWheelPos = 9
                    mStartTime = mTodayday
                    mEndTime = mTodayday
                    initUI()
                    initCustomTime()
                }
            }
            R.id.tv_start -> {
                if (timeCurrent != 0) {
                    timeCurrent = 0
                    initCustomTime()
                }
            }
            R.id.tv_end -> {
                if (timeCurrent != 1) {
                    timeCurrent = 1
                    initCustomTime()
                }
            }

            R.id.tv_sure -> {
                if (mWheelPos == 9) {
                    val days = TimeUtil.getDaysBetweenDates(mStartTime, mEndTime, "yyyy-MM-dd")
                    if (days > 29) {
                        showToast("请选择30天内数据对比")
                        return
                    }
                    val result = YgxUtilsKt.compareDates(mStartTime, mEndTime)
                    when (result) {
                        0 -> {//两个日期相同
                            if (mStartTime == mTodayday) {
                                mWheelPos = 0
                            } else {
                                mWheelPos = 3
                            }
                        }
                        1 -> {//第一个日期晚于第二个日期
                            val tempTime = mStartTime
                            mStartTime = mEndTime
                            mEndTime = tempTime
                            val po1 = mWheelStartPosition1
                            val po2 = mWheelStartPosition2
                            val po3 = mWheelStartPosition3
                            mWheelStartPosition1 = mWheelEndPosition1
                            mWheelStartPosition2 = mWheelEndPosition2
                            mWheelStartPosition3 = mWheelEndPosition3
                            mWheelEndPosition1 = po1
                            mWheelEndPosition2 = po2
                            mWheelEndPosition3 = po3
                            initTagView()
                        }
                        else -> {
                        }
                    }
                }
                if (mWheelPos == 3 && mStartTime == mTodayday) {
                    mWheelPos = 0
                }
                if (mWheelPos == 4) {//按月
                    val month =
                        mAllBeans?.get(mWheelPosition1)?.telSecondCategories?.get(mWheelPosition2)?.name
                            ?: ""
                    if (mMonth == month) {
                        mWheelPos = 2
                    }
                }
                positionListener?.onClick(
                    currentTopProvin,
                    mWheelPosition1,
                    mWheelPosition2,
                    mWheelPosition3,
                    mWheelStartPosition1,
                    mWheelStartPosition2,
                    mWheelStartPosition3,
                    mWheelEndPosition1,
                    mWheelEndPosition2,
                    mWheelEndPosition3,
                    mWheelPos ?: 0,
                    data = "${mStartTime}_$mEndTime"
                )
                dismiss()
            }
        }
    }

    private fun getWheelCurrentTime() {
        mWheelPosition1 = wheelLinkage?.firstWheelView?.currentPosition ?: 0
        mWheelPosition2 = wheelLinkage?.secondWheelView?.currentPosition ?: 0
        mWheelPosition3 = wheelLinkage?.thirdWheelView?.currentPosition ?: 0

        val month =
            mAllCusBeans?.get(mWheelPosition1)?.telSecondCategories?.get(mWheelPosition2)?.name
        val time = "${mAllCusBeans?.get(mWheelPosition1)?.name}-${month}-${
            mAllCusBeans?.get(mWheelPosition1)?.telSecondCategories?.get(
                mWheelPosition2
            )?.telThirdCategories?.get(mWheelPosition3)?.name
        }"
        mStartTime = time
        mEndTime = time
    }


}